//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.滑动窗口.定长滑动窗口;

import java.util.Arrays;

public class demo_2090 {
    public demo_2090() {
    }

    public static void main(String[] args) {
        int[] nums = new int[]{7, 4, 3, 9, 1, 8, 5, 2, 6};
        int[] c = getAverages(nums, 3);

        for(int j : c) {
            System.out.print(j + "  ");
        }

    }

    public static int[] getAverages(int[] nums, int k) {
        int[] avgs = new int[nums.length];
        Arrays.fill(avgs, -1);
        long sum = 0L;
        if (k == 0) {
            return nums;
        } else if (2 * k + 1 > nums.length) {
            return avgs;
        } else {
            for(int i = 0; i < nums.length; ++i) {
                sum += (long)nums[i];
                if (i - k < 0) {
                    avgs[i] = -1;
                } else if (i >= 2 * k) {
                    avgs[i - k] = (int)(sum / (long)(2 * k + 1));
                    sum -= (long)nums[i - 2 * k];
                }
            }

            return avgs;
        }
    }
}
